package cn.lizemin.config;

import cn.lizemin.intercetors.MyInterceptor1;
import cn.lizemin.intercetors.MyInterceptor2;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author lzm
 * @version 1.0
 * @description: TODO
 * @date 2022/1/5 20:51
 */
@Configuration
public class MvcConfig implements WebMvcConfigurer {
    /**
     * 配置拦截器相关方法
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new MyInterceptor1())   //指定拦截器
                .addPathPatterns("/**")    //拦截所有请求
                .excludePathPatterns("/file/**")
                .order(8);

        registry.addInterceptor(new MyInterceptor2())
                .addPathPatterns("/**")    //拦截所有请求
                .excludePathPatterns("/file/**") //放行跟文件有关的请求
                .order(1); //指定拦截器执行顺序 int 类型数字: 默认按照自然排序执行  数字相同时,按照配置顺序执行

//       拦截器的执行顺序： 1,4,5,2,6,3

    }
}
